const app = require("express")();

/**
 * A song type
 * @typedef {object} Song
 * @property {string} title.required - The title
 * @property {string} artist - The artist
 * @property {number} year - The year - double
 * @property {boolean} isYes - The isYes
 */

/**
 * GET /test
 * @tags 接口分类 
 * @summary 接口标题
 * @description 接口描述
 * @param {string} name.param - name param description
 * @param {number} age.query.required - name param description
 * @param {Song} book.query.required - songs info
 * @return {array<Song>} 200 - success response - application/json
 * @return {object} 400 - Bad request response
 * @example response - 200 - success response example
 * [
 *   {
 *     "title": "Bury the light",
 *     "artist": "Casey Edwards ft. Victor Borba",
 *     "year": 2020,
 *     "isYes":false
 *   }
 * ]
 */
app.get("/test", async (req, res) => {
	try {
		console.log('访问成功！'.green)
		res.API('访问成功！');
	} catch (err) {
		res.API_ERROR(err.msg, 1002, err?.mapped?.());
	}
});

/**
 * POST /testPost
 * @tags 接口分类 
 * @summary 接口标题
 * @description 接口描述
 * @param {Song} request.body.required - songs info
 * @return {array<Song>} 200 - success response - application/json
 * @return {object} 400 - Bad request response
 * @example response - 200 - success response example
 * [
 *   {
 *     "title": "Bury the light",
 *     "artist": "Casey Edwards ft. Victor Borba",
 *     "year": 2020,
 *     "isYes":false
 *   }
 * ]
 */
app.post("/testPost", async (req, res) => {
	try {
		res.API(req.body);
	} catch (err) {
		res.API_ERROR(err.msg, 1002, err?.mapped?.());
	}
});

module.exports = app;
